package com.icinfo.cloud.provider.common.crontask;

import com.icinfo.cloud.provider.punish.actscode.service.ICaseActsCodeErrInfoService;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseMainInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * 案件主表时效颜色定时
 * @author liyafeng
 * @date 2023/4/12
 */
@Configuration
@EnableScheduling
@Slf4j
@RestController
@RequestMapping("/caseMainInfoTimeColorInitTask")
public class CaseMainInfoTimeColorInitTask {
    private static final String CASE_MAIN_INFO_TIME_COLOR_REDIS_KEY = "PUNISH:CASE_ACTCODE_RESAVE_REDIS_KEY";
    @Resource
    private RedisTemplate<String, String> redisTemplate;
    @Resource
    private ICaseMainInfoService caseMainInfoService;


    /**
     * 案件主表时效颜色定时初始化
     * @author liyafeng
     * @date 2023/4/12
      * @param
     * @return
     */
    @Scheduled(cron = "0 10 0 * * ?")
    public void reSaveCaseActsCodeInfo() {
        //防止多台服务器重复执行（过期时间设置为10分钟，预防服务器时间不同步）
        if (!redisTemplate.opsForValue().setIfAbsent(CASE_MAIN_INFO_TIME_COLOR_REDIS_KEY, CASE_MAIN_INFO_TIME_COLOR_REDIS_KEY, 10, TimeUnit.MINUTES)) {
            log.info("--------当前服务器未拿到分布式锁，不执行逻辑----------");
            return;
        }
        caseMainInfoService.initCaseTimeColor();
    }


}
